package com.zone.vehicle.superapp.view;

import android.app.Application;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.util.Log;

import com.saicmotor.pay.db.PayDaoManager;
import com.tamsiree.rxkit.RxBroadcastTool;
import com.tamsiree.rxkit.RxTool;
import com.zone.lib.download.DownloadConstant;
import com.zone.lib.download.db.DownloadDaoManager;
import com.zone.lib.download.enums.AppStatusEnum;
import com.zone.sdk_api.ApiManager;
import com.zone.sdk_api.common.Content;
import com.zone.vehicle.sdk.module.superapp.vehicle.utils.NetUtil;
import com.zone.vehicle.superapp.common.ContentAccount;
import com.zone.vehicle.superapp.utils.LoginUtil;
import com.zone.vehicle.superapp.utils.SharedPreferencesUtil;
import com.zone.vehicle.superapp.view.receiver.SuperAppReceiver;
import com.zone.vehicle.superapp.view.service.SupperService;

public class SuperApplication extends Application {

    private static final String TAG = SuperApplication.class.getSimpleName();

    private static SuperApplication application;

    public static int NET_STATUS = NetUtil.NETWORK_WIFI;
    public static final String ACTION_APP_START = "ACTION_APP_START";

    private SupperService supperService;

    public static SuperApplication getInstance(){
        return application;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        application = this;
        RxTool rxTool = RxTool.init(this)
                .debugLog(true)
                .debugLogFile(true)
                .crashLogFile(true);
        rxTool.crashProfile().enabled(true).logErrorOnRestart(false);
        DownloadDaoManager.getInstance().init(this);
        PayDaoManager.getInstance().init(this);
        ApiManager.init(Content.URL_SERVER, getApplicationContext());//account QA
        LoginUtil.getInstance().init(this);
        SharedPreferencesUtil.getInstance(this).putSP(Content.VIN, Content.VIN_TEST);
        ApiManager.getInstance().setHeader(Content.VIN, Content.VIN_TEST);
        ApiManager.getInstance().setHeader(Content.X_DEVICE_FROM, Content.VIN_TEST);
        ApiManager.getInstance().setHeader(Content.X_DEVICE_ID, Content.VIN_TEST);
    }

    public void reStartDigitalService(){
        if (supperService != null){
            supperService.reStartDigitalService();
        }
    }

    private void startService(){
//        bindService(new Intent(this, SupperService.class), conn, BIND_AUTO_CREATE);
        startService(new Intent(this, SupperService.class));
    }

//    private ServiceConnection conn = new ServiceConnection() {
//        @Override
//        public void onServiceConnected(ComponentName name, IBinder binder) {
//            Log.i(TAG, " onServiceConnected ");
//            supperService = ((SupperService.SuperServiceBinder) binder).getService();
//        }
//
//        @Override
//        public void onServiceDisconnected(ComponentName name) {
//            Log.i(TAG, " onServiceDisconnected ");
//            supperService = null;
//        }
//    };

}
